package com.bsh.repository;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.bsh.api.ApiUtils;
import com.bsh.mybatis.IRepository.PaymentMapper;
import com.bsh.mybatis.model.Payment;
import com.bsh.utils.JdbcHelper;

@Repository
public class DaoPayment {
	@Resource
	SqlSessionTemplate session;
	
	PaymentMapper getPaymentMapper(){
		return session.getMapper(PaymentMapper.class);
	}
	
	@Resource
	JdbcTemplate jdbcTemplate;
	
	@Resource
	NamedParameterJdbcTemplate namedJdbcTemplate;
	
	@Resource
	JdbcHelper jh;
	

	PaymentMapper getMapper() {
		return session.getMapper(PaymentMapper.class);
	}
 

	public List<Map<String, Object>> getPaymentList(String type){
		
		List<Map<String, Object>> row = getMapper().getOnlinePaymentList();
		
		return row;
	}
	
	public Integer updatePaymentTotal(Payment record){
		return getMapper().updatePaymentTotal(record);
	}


	public Payment getPaymentByClassName(String className) {
		Payment row = getMapper().getPaymentByClassName(className);
		return row;
	}
	
	public Payment getPaymentById(Integer paymentId) {
		Payment row = getMapper().getPaymentById(paymentId);
		return row;
	}
    /**
     * 按用途查询支付方式
     * @param useage
     * @return
     */
	public List<Map<String, Object>> getPaymentListByUseage(String useage){
		StringBuffer sb = new StringBuffer();
		sb.append(" SELECT class_name as className,name FROM payment where is_show=1  ");
		if (ApiUtils.objIsNotEmpty(useage)) {
			sb.append(String.format(" AND useage like '%%%s%%'",useage));
		}
		sb.append(" ORDER BY id ASC ");
		return jh.getList(sb.toString());
	}

}
